package main

import (
	"encoding/json"
	"fmt"
)

type person struct {
	Name string `json:"nameq"`
	Age  int
}

func main() {
	p1 := person{
		Name: "stormfat",
		Age:  41,
	}
	//ret := make([]byte, 4096)
	ret, err := json.Marshal(p1)
	if err != nil {
		fmt.Println("err", err)
		return
	}
	fmt.Printf("%v\n", string(ret))

	//反序列化
	str := `{"name":"stormfat","age:":11}`
	var p2 person
	json.Unmarshal([]byte(str), &p2) //用&表示修改p2所指向地址中的数据
	fmt.Printf("%#v\n", p2)
}
